using UnityEngine;
using System.Collections;

/// \class  gkDestroyOnDeathEvent
/// \brief  Handle the player death event
[AddComponentMenu("GK/Engine/Game/Destruction/gkDestroyOnDeathEvent")]
[RequireComponent(typeof(gkEventComponent))]
public class gkDestroyOnDeathEvent : MonoBehaviour 
{	
	/// \brief  Called when the component is enabled
	void OnEnable() 
	{
		// Listen the shock event of the owner
		GetComponent<gkEventComponent>().AddEventHandler(gkLifeEvent.Death, HandleDeathEvent);
	}
	
	/// \brief  Called when the component is disabled
	void OnDisable() 
	{	
		// Remove the shock event of the owner
		GetComponent<gkEventComponent>().RemoveEventHandler(gkLifeEvent.Death, HandleDeathEvent);
	}
	
	/// Handle the player death event
	void HandleDeathEvent(Object a_rEvent)
	{
		// Auto-destroy
		Destroy(gameObject);
	}
}